﻿/*
 * @Autor: PK
 * @Date: 2022/01/27 09:42:SS
 */

using System;
using O2DESNet.Distributions;
using ShkSimulation.core.template.agency;
using ShkSimulation.core.template.customer;

namespace ShkSimulation.carsharing.impl.elements {

	public class ReserveAgency: InternalAgency {

		public override InternalAgencyServeTime ServeTime { get; set; } = InternalAgencyServeTime.BeforeArrive;

		private Random random = new Random();
		private readonly TimeSpan avgReserveTime;

		public ReserveAgency(double avgReserveTime) {
			this.avgReserveTime = TimeSpan.FromMinutes(avgReserveTime);
		}

		public override InternalServeResult BeforeParentArrive(Customer customer) {
			if (customer is Traveler traveler && traveler.Vehicle != null) {
				return InternalServeResult.Continue();
			}
			TimeSpan timeSpan = Exponential.Sample(random, avgReserveTime);
			return InternalServeResult.ScheduledFinish(ClockTime + timeSpan);
		}

		public override InternalServeResult BeforeParentServe(Customer customer) {
			throw new NotImplementedException();
		}

		public override InternalServeResult BeforeParentDepart(Customer customer) {
			throw new NotImplementedException();
		}

	}

}